<?php
header("Content-Type: text/html; charset=UTF-8");
include "TopSdk.php";
date_default_timezone_set('Asia/Shanghai'); 
$q=$_GET['q'];
$p=$_GET['p'];
$c = new TopClient;
$c->appkey = '24798316';
$c->secretKey = 'b60868c5ab3157899d9b0cfa05325669';
$req = new TbkItemGetRequest;
$req->setFields("num_iid,title,pict_url,small_images,reserve_price,zk_final_price,user_type,provcity,item_url,seller_id,volume,nick");
 
$req->setQ("$q");
 
$req->setCat("");
$req->setItemloc("杭州");
//$req->setSort("tk_rate_des");
$req->setIsTmall("true");
$req->setIsOverseas("false");
$req->setStartPrice("0");
$req->setEndPrice("10000");
 
$req->setPlatform("1");
 
 
$req->setPageNo("$p");
$req->setPageSize("100");
$resp = $c->execute($req);

 
 
$goods_list=object_to_array($resp);
 
//echo '<pre>';
                            //[item_url] => http://item.taobao.com/item.htm?id=555865771584
                             //[nick] => zhuquandian
                             //[num_iid] => 555865771584
                             //[pict_url] => https://img.alicdn.com/tfscom/i3/895071549/TB2au.0aTIlyKJjSZFrXXXn2VXa_!!895071549.jpg
                             //[provcity] => 姹熻嫃 寰愬窞
                             //[reserve_price] => 19.90
                            // [seller_id] => 895071549
                            // [small_images] => Array
                            //     (
                               //      [string] => Array
                                 //        (
                                //             [0] => https://img.alicdn.com/tfscom/i3/895071549/TB2EsEWaQ7myKJjSZFkXXa3vVXa_!!895071549.jpg
                                //             [1] => https://img.alicdn.com/tfscom/i2/895071549/TB2NMsUaQ7myKJjSZFgXXcT9XXa_!!895071549.jpg
                                  //           [2] => https://img.alicdn.com/tfscom/i2/895071549/TB29plTaBAOyuJjy0FlXXcaxFXa_!!895071549.jpg
                                  //           [3] => https://img.alicdn.com/tfscom/i2/895071549/TB2hjZZagojyKJjy0FaXXakspXa_!!895071549.jpg
                                  //       )

                               //  )

                           //  [title] => 2017绉嬪啲濂宠鏂版闊╃増淇韩鏄ュ鎵撳簳琛函鑹查拡缁囪～濂虫瘺琛ｅ崐楂橀涓婅。
                            // [user_type] => 0
                            // [volume] => 0
                            // [zk_final_price] => 19.90
 echo '<ul>';
 
 if(!empty($goods_list['results']['n_tbk_item'])){
	foreach($goods_list['results']['n_tbk_item']   as $key=>$value){
 
	echo '<li style="float:left"><a href="'.$value['item_url'].' ">';
	echo '<img style="width:300px;" src="'.$value['pict_url'].' "/><br/>';
	echo '店家：'.$value['nick'] ;
	
	echo '</a></li>';
}  
 }

echo '</ul>';



/**
 * 对象 转 数组
 *
 * @param object $obj 对象
 * @return array
 */
function object_to_array($obj) {
    $obj = (array)$obj;
    foreach ($obj as $k => $v) {
        if (gettype($v) == 'resource') {
            return;
        }
        if (gettype($v) == 'object' || gettype($v) == 'array') {
            $obj[$k] = (array)object_to_array($v);
        }
    }
 
    return $obj;
}